<template>
  <s-layout :bgStyle="{ color: '#090909' }">
    <image class="commodity" src="@/static/img/officerDetail/img-3.png"></image>
    <view class="officerDetail">
      <view class="product">
        <view class="product-t">米其林汽车轮胎</view>
        <view class="product-b ss-flex ss-col-center">
          <view class="ss-flex">
            <view class="text-1">系列：</view>
            <view class="text-2">数字形象</view>
          </view>
          <view class="ss-flex">
            <view class="text-1">限量/</view>
            <view class="text-2">50000</view>
          </view>
        </view>
      </view>
      <view class="issuer ss-flex">
        <image class="issuer-l" src="@/static/img/officerDetail/img-1.png"></image>
        <view class="issuer-r">
          <view class="text-1">发行方</view>
          <view class="text-2">九丝城宇宙</view>
        </view>
      </view>
      <view class="sales">
        <view class="tab ss-flex">
          <view @tap="sales=0" :class="{'active':sales===0}">集售信息</view>
          <view @tap="sales=1" :class="{'active':sales===1}">集售历史</view>
        </view>
        <view class="aggregation" v-if="sales===0">
          <view class="ss-flex ss-col-center ss-row-between">
            <view class="text-1">
              <view>起始价格</view>
              <view>价格幅度</view>
              <view>开始时间</view>
            </view>
            <view class="text-2">
              <view>500.00</view>
              <view>±1.20%</view>
              <view>2024-01-01 11:10:02</view>
            </view>
          </view>
          <view class="rulesTitle">
            集售规则
          </view>
          <view class="rules">
            <view>1、当前藏品目前处于孵化阶段，用户最多可持有40份，拆配价为1500元;
            </view>
            <view class="ss-flex">
              <view class="ss-flex-1" :class="{'ellipsis-container':expanded===false}">
                2:交易时间:可挂单时间0:05一12:00，可购买当前藏品目前处于孵化阶段，用户最多可持有40份，拆配价为1500元;
                2:交易时间:可挂单时间0:05一12:00，可购...
                <text v-if="expanded===true" class="expand" @tap="toggleExpand">收起</text>
              </view>
              <view v-if="expanded===false" class="expand" @tap="toggleExpand">展开</view>
            </view>
          </view>

        </view>
        <view class="history" v-if="sales===1"></view>
      </view>


      <view class="product-content">
        <view class="tab ss-flex">
          <view @tap="active=0" :class="{'active':active===0}">商品详情</view>
          <view @tap="active=1" :class="{'active':active===1}">权益介绍</view>
        </view>
        <view class="productDetails" v-if="active===0">
          <image mode="widthFix" src="@/static/img/pro-icon-1.png"></image>
        </view>
        <view class="commodityRights" v-if="active===1">
          <view class="title">商品权益</view>
          <view class="introduce">
            <view v-for="item in commodityRightsList" :key="item.id" class="ss-flex">
              <view class="text-1">{{ item.title }}</view>
              <view class="ss-flex-1 text-2">{{ item.text }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <su-fixed bottom :val="0" :isInset="false">
      <view class="officialDetail-footer ss-flex ss-col-center ss-row-between">
        <view class="footer-left ss-flex ss-col-bottom">
          <view class="text-price">500.00</view>
        </view>
        <view class="footer-right ss-flex ss-col-center">
          <button class="btn-1" @tap="onSold">出售</button>
          <button class="btn-2" @tap="state.showCoupon = true">购买</button>
        </view>
      </view>
    </su-fixed>
    <PopupBuyCollection v-model="state.couponInfo"
                        :show="state.showCoupon"
                        @confirm="onConfirm"
                        @close="state.showCoupon = false"></PopupBuyCollection>
  </s-layout>
</template>

<script setup>
  import sheep from '@/sheep';
  import { reactive, ref } from 'vue';
  import PopupBuyCollection from './components/popup-buyCollection/index.vue';
  import { onLoad } from '@dcloudio/uni-app';
  onLoad((options)=>{
    state.goodsId = options.id;
    getData()
  })
  const active = ref(0);
  const sales = ref(0);
  const expanded = ref(false);
  const state = reactive({
    goodsId: '',
    showCoupon: false,
    couponInfo: [],
    showDiscount: false,
  });
  const commodityRightsList = ref([
    {
      title: '商品名称',
      text: '米其林汽车轮胎',
      id: 0,
    }, {
      title: '流转方式',
      text: '品牌孵化',
      id: 1,
    }, {
      title: '拆配周期',
      text: '93天/轮*4',
      id: 2,
    }, {
      title: '孵化上市',
      text: '2024年4月17日',
      id: 3,
    }, {
      title: '孵化上限',
      text: '40份',
      id: 4,
    }, {
      title: '预期收益',
      text: '3%',
      id: 5,
    }, {
      title: '收益周期',
      text: 'D+8天/次',
      id: 6,
    }, {
      title: '孵化退市',
      text: '2025年4月24日',
      id: 7,
    },
  ]);
  const toggleExpand = () => {
    expanded.value = !expanded.value;
  };

  function onConfirm() {
    state.showCoupon = false;
    sheep.$router.go('/pages/brand/confirm');
  }

  function onSold() {
    sheep.$router.go('/pages/brand/sold');
  }

  // 获取详情
  const getData = async () => {
    const { code, data } = await sheep.$api.goods.detail(state.goodsId);
    if (code === 1) {
      console.log(data);
    }
  };
</script>

<style lang="scss" scoped>
  .officerDetail {
    padding: 15px 15px 110px;
    box-sizing: border-box;
    background-color: #090909;


    .product {
      background: #1C1C1E;
      border-radius: 10px;
      padding: 18px 20px 19px;
      box-sizing: border-box;

      .product-t {
        font-weight: 400;
        font-size: 20px;
        color: #FFFFFF;
        margin-bottom: 14.5px;
      }

      .product-b {
        font-weight: 400;
        font-size: 14px;

        .text-1 {
          color: #939393;
        }

        .text-2 {
          color: #13C093;
        }

        view {

        }
      }
    }

    .issuer {
      background: #1C1C1E;
      border-radius: 10px;
      padding: 14px 15px;
      box-sizing: border-box;
      height: 70px;
      margin: 10px 0;

      .issuer-l {
        width: 43px;
        height: 43px;
        border-radius: 50%;
        margin-right: 9px;
      }

      .issuer-r {
        .text-1 {
          font-weight: 400;
          font-size: 16px;
          color: #FFFFFF;
          margin-bottom: 6px;
        }

        .text-2 {
          font-weight: 400;
          font-size: 10px;
          color: #888888;
        }
      }
    }

    .sales {
      background: #1C1C1E;
      border-radius: 10px;
      padding: 24px 15px;
      box-sizing: border-box;
      margin-bottom: 11px;

      .tab {
        padding: 0 4px;
        box-sizing: border-box;
        font-weight: 400;
        font-size: 18px;
        color: #767676;
        margin-bottom: 25px;

        view {
          margin-right: 20px;
        }

        .active {
          color: #FFFFFF;
        }

      }

      .aggregation {
        .rules {
          > view {
            font-weight: 300;
            font-size: 12px;
            color: #FFFFFF;

            &:not(:last-child) {
              margin-bottom: 20px;
            }
          }

          .ellipsis-container {
            white-space: nowrap; /* 让文本在一行内显示 */
            overflow: hidden; /* 隐藏超出部分 */
            text-overflow: ellipsis; /* 显示省略号 */
          }

          .expand {
            color: #13C093;
          }
        }

        .rulesTitle {
          font-weight: 300;
          font-size: 14px;
          color: #939393;
          margin-bottom: 19px;
        }

        .text-1 {
          font-weight: 300;
          font-size: 14px;
          color: #939393;

          view {
            margin-bottom: 15px;
          }
        }

        .text-2 {
          font-weight: 300;
          font-size: 14px;
          color: #FFFFFF;
          text-align: right;

          view {
            margin-bottom: 15px;
          }
        }
      }

      .history {
      }
    }

    .product-content {
      background: #1C1C1E;
      border-radius: 10px;
      padding: 24px 15px;
      box-sizing: border-box;

      .tab {
        padding: 0 4px;
        box-sizing: border-box;
        font-weight: 400;
        font-size: 18px;
        color: #767676;
        margin-bottom: 25px;

        view {
          margin-right: 20px;
        }

        .active {
          color: #FFFFFF;
        }

      }

      .productDetails {
        image {
          width: 100%;
        }
      }

      .commodityRights {
        .title {
          padding: 13px 12px;
          box-sizing: border-box;
          height: 40px;
          background: #221D1A;
          font-weight: 400;
          font-size: 14px;
          color: #DFB581;
        }

        .introduce {
          > view {
            height: 40px;
            line-height: 40px;
            text-align: center;
            background: #15110E;
            border-bottom: 1px solid #2F2933;
          }

          .text-1 {
            width: 96px;
            font-weight: 300;
            font-size: 13px;
            color: #DFB581;
            border-right: 1px solid #2F2933;
          }

          .text-2 {
            font-weight: 300;
            font-size: 12px;
            color: #AC8866;
          }
        }
      }
    }
  }

  .commodity {
    width: 100%;
    height: 375px;
  }

  .officialDetail-footer {
    padding: 19px 16px;
    box-sizing: border-box;
    height: 75px;
    background: #151515;

    .footer-left {
      .text-price {
        font-weight: 500;
        font-size: 18px;
        color: #FFFFFF;
      }
    }

    .footer-right {
      .btn-1 {
        width: 90px;
        height: 38px;
        line-height: 38px;
        text-align: center;
        border-radius: 19px;
        border: 1px solid #FFFFFF;
        font-weight: 500;
        font-size: 16px;
        color: #FFFFFF;
        background-color: transparent;
        margin-right: 11px;
      }

      .btn-2 {
        width: 90px;
        height: 38px;
        line-height: 38px;
        text-align: center;
        border-radius: 19px;
        font-weight: 500;
        font-size: 16px;
        color: #FFFFFF;
        background: linear-gradient(90deg, #45C9F0, #36F6AF);
      }

    }
  }


</style>
